package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.OperationMapper;
import com.yxuan.springboot.model.Operation;
import com.yxuan.springboot.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 
 * @author zchao
 *    Operation业务层实现类
 * @date 2023-05-14 20:40:39
 */
@Service
@Transactional
public class OperationServiceImpl extends BaseServiceImpl<Operation> implements OperationService {

    @Autowired
    private OperationMapper operationMapper;

    /**
     * @methodName addOOperation
     * @effect: 用户对文章进行操作
     */
    @Override
    public Integer addOperation(Operation operation) throws Exception {
        //1.根据对象查询是有历史数据
        Operation queryOperation = operationMapper.queryObjectByPramas(operation);
        //2.如果有历史数据，则直接修改状态
        Integer num = 0 ;
        if (queryOperation != null){
            queryOperation.setDeleteState("0");
            //修改数据
            num =  operationMapper.update(queryOperation);
        }else {
            operation.setDeleteState("0");
            //添加数据
            num =  operationMapper.insert(operation);
        }
        return num;
    }
}
